# coding: UTF-8

import urllib
from google.appengine.api import urlfetch
from django.utils import simplejson
import logging

class GeoCoder:

    def __init__(self, appid, datum='wgs'):
        self.appid = appid
        self.datum = 'wgs'
        self.url = 'http://geo.search.olp.yahooapis.jp/OpenLocalPlatform/V1/geoCoder'

    def search_query(self, query, result=10, start=1):
        url = self.url 
        url +=  '?' + urllib.urlencode({
              'appid'   : self.appid ,
              'datum'   : self.datum,
              'output'  : 'json',
              'query'   : query.encode("utf-8"),
              'result'  : result,
              'start'   : start,
              })
        logging.info(url)
        result = urlfetch.fetch( url , method=urlfetch.GET)
        return simplejson.loads( result.content )       
 
